//package com.skl.config;
//
//import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
//@Configuration
//public class GatewayConfig {
//    //ip限流
//    @Bean
//    public KeyResolver ipKeyResolver(){
////        return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getHostName());//简单写法
//        return new KeyResolver() {
//            @Override
//            public Mono<String> resolve(ServerWebExchange exchange) {
//                //exchange对象可以获取到请求信息，如果想根据用户做限流，可以通过exchange获取当前请求的用户id或者用户名
//                //如果需要根据特定接口uri进行限流，则需要获取请求地址的uri作为限流key（exchange.getRequest().getPath().value()）
//                return Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
//            }
//        };
//    }
//}
